﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using StateGrid;
using StateGrid.MDBservice;

namespace StateGrid.MDBservice
{
    /// <summary>
    /// 学位论文服务，表名必须为xw.mdb
    /// </summary>
    public class XWService : MDBservice
    {
        /// <summary>
        /// 设置XW表中的字段信息列表
        /// </summary>
        override void setColumnList()
        {
            this.ColumnList = new List<Column>();
            
            this.ColumnList.Add(new Column("中文题名", OleDbType.WChar, 255));
            this.ColumnList.Add(new Column("英文题名", OleDbType.WChar, 255));
            this.ColumnList.Add(new Column("作者", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("导师", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("论文级别", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("学科专业名称", OleDbType.WChar, 150));
            this.ColumnList.Add(new Column("分类号", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("学位授予单位", OleDbType.WChar, 250));
            this.ColumnList.Add(new Column("论文提交日期", OleDbType.Date));
            this.ColumnList.Add(new Column("论文答辩日期", OleDbType.Date));
            this.ColumnList.Add(new Column("中文关键词", OleDbType.WChar, 255));
            this.ColumnList.Add(new Column("中文摘要", OleDbType.WChar,0));
            this.ColumnList.Add(new Column("英文摘要", OleDbType.WChar,0));
            this.ColumnList.Add(new Column("年份", OleDbType.WChar, 4));
            this.ColumnList.Add(new Column("英文关键词", OleDbType.WChar, 255));
            this.ColumnList.Add(new Column("原文件名", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("出版日期", OleDbType.Date));
            this.ColumnList.Add(new Column("页数", OleDbType.WChar, 10));
            this.ColumnList.Add(new Column("学位授予日期", OleDbType.Date));
            this.ColumnList.Add(new Column("分类编码", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("索引编码", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("文件名", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("分类体系", OleDbType.WChar, 50));
            this.ColumnList.Add(new Column("更新日期", OleDbType.Date));
            this.ColumnList.Add(new Column("全文", OleDbType.WChar, 50));
        }

        /// <summary>
        /// 从Access数据库中读取XW表的信息
        /// </summary>
        /// <returns></returns>
        public List<XW> getXWList()
        {
            List<XW> result = new List<XW>();

           

            //打开连接
            this.openOleDbConnection();

            //sql语句
            OleDbCommand sqlcmd = new OleDbCommand(@"select * from xw", this.ObjConnection);

            //执行查询
            OleDbDataReader reader = sqlcmd.ExecuteReader();

            while (reader.Read())
            { //这个read调用很重要！不写的话运行时将提示找不到数据
                XW temp = new XW();
                temp.Xw_zwtm = reader["中文题名"].ToString();
                temp.Xw_ywtm = reader["英文题名"].ToString();
                temp.Xw_zz = reader["作者"].ToString();
                temp.Xw_ds = reader["导师"].ToString();
                temp.Xw_lwjb = reader["论文级别"].ToString();
                temp.Xw_xkzymc = reader["学科专业名称"].ToString();
                temp.Xw_flh = reader["分类号"].ToString();
                temp.Xw_xwsydw = reader["学位授予单位"].ToString();
                try
                {
                    temp.Xw_lwtjrq = DateTime.Parse(reader["论文提交日期"].ToString());
                }
                catch (Exception)
                {
                }
                try
                {
                    temp.Xw_lwdbrq = DateTime.Parse(reader["论文答辩日期"].ToString());
                }
                catch (Exception)
                {
                }
                temp.Xw_zwgjc = reader["中文关键词"].ToString();
                temp.Xw_zwzy = reader["中文摘要"].ToString();
                temp.Xw_ywzy = reader["英文摘要"].ToString();
                temp.Xw_nf = reader["年份"].ToString();
                temp.Xw_ywgjc = reader["英文关键词"].ToString();
                temp.Xw_ywjm = reader["原文件名"].ToString();
                try
                {
                    temp.Xw_cbrq = DateTime.Parse(reader["出版日期"].ToString());
                }
                catch (Exception)
                {
                }
                temp.Xw_ys = reader["页数"].ToString();
                try
                {
                    temp.Xw_xwsyrq = DateTime.Parse(reader["学位授予日期"].ToString());
                }
                catch (Exception)
                {
                }
                temp.Xw_flbm=reader["分类编码"].ToString();
                temp.Xw_sybm = reader["索引编码"].ToString();
                temp.Xw_wjm = reader["文件名"].ToString();
                temp.Xw_fltx=reader["分类体系"].ToString();
                try
                {
                    temp.Xw_gxrq = DateTime.Parse(reader["更新日期"].ToString());
                }
                catch (Exception)
                {
                }

                temp.Xw_qw=reader["全文"].ToString();
                result.Add(temp);
            }
            reader.Close();
            return result;
        }

        /// <summary>
        /// 验证表名是否为XW
        /// </summary>
        /// <returns></returns>
        public String validateTableName()
        {
            String result = "对不起，您所选的数据库中不存在表名为：“XW”的表！！！";
            //建立连接
            this.openOleDbConnection();

            //获取数据库中的表名
            DataTable shemaTable =this.ObjConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new Object[]{ null, null, null, "TABLE"});

            //获取记录总行数
            int count = shemaTable.Rows.Count;
            //获取表名是第几列
            int column = shemaTable.Columns.IndexOf("TABLE_NAME");
            for (int i = 0; i < count; i++)
            {
                DataRow dataRow = shemaTable.Rows[i];
                if (dataRow.ItemArray.GetValue(column).ToString().ToUpper().Equals("XW"))
                {
                    result = null;
                    break;
                }
            }

            ObjConnection.Close();

            return result;
        }

        /// <summary>
        /// 验证XW表中字段是否全部有效
        /// </summary>
        /// <returns></returns>
        public List<ColumnError> validateTableColums()
        {
            List<ColumnError> result = new List<ColumnError>();
            //打开Access数据库连接
            this.openOleDbConnection();

            //获取数据库中的表名
            DataTable columnsTable = this.ObjConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new Object[] { null, null, "XW",null });
            int count = columnsTable.Rows.Count;
            int nameColumn = columnsTable.Columns.IndexOf("COLUMN_NAME");
            int typeColumn = columnsTable.Columns.IndexOf("DATA_TYPE");
            int lengthColumn = columnsTable.Columns.IndexOf("CHARACTER_MAXIMUM_LENGTH");


            ColumnError error = null;
            foreach (XWColumn temp in this.ColumnList)
            {
                Boolean flag = true;
                for (int i = 0; i < count; i++)
                {
                    DataRow dataRow = columnsTable.Rows[i];
                    //获取字段类型
                    OleDbType type = (OleDbType)dataRow.ItemArray.GetValue(typeColumn);
                    //获取字段名称
                    String name = dataRow.ItemArray.GetValue(nameColumn).ToString();
                    //如果类型为Date或列名是“中文摘要”或者是“英文摘要”，则找到了；否则，继续判断字段长度
                    if (temp.ColumnName.Equals(name))
                    {
                        flag = false;
                        if (temp.ColumnType == type)
                        {
                            Int32 length;
                            Int32.TryParse(dataRow.ItemArray.GetValue(lengthColumn).ToString(), out length);
                            if (temp.ColumnType == OleDbType.Date || temp.ColumnName.Equals("中文摘要") || temp.ColumnName.Equals("英文摘要") || temp.ColumnLength == length)
                            {
                                break;
                            }
                            else
                            {
                                error = new ColumnError();
                                error.Column = temp.ColumnName;
                                error.Error="实际字段长度为"+temp.ColumnLength+"；而给出的字段长度为"+length;
                            }
                        }
                        else
                        {
                            error = new ColumnError();
                            error.Column = temp.ColumnName;
                            error.Error = "实际类型为"+temp.ColumnType+"；而给出的字段长度为"+type;
                        }
                        result.Add(error);
                        break;
                    }
                }
                if (flag)
                {
                    error = new ColumnError();
                    error.Column = temp.ColumnName;
                    error.Error = "没有找到该字段";
                    result.Add(error);
                }
            }
            return result;
        }

        /// <summary>
        /// 规整字段
        /// </summary>
        /// <param name="xw">要规整的记录</param>
        /// <returns>反馈规整信息，规整错误</returns>
        public List<String> formatData()
        {
            //反馈信息
            List<String> result=new List<string>();
            //获取学位分类表
            Hashtable hash = new XW_CATALOGService().getXW_CATALOGHash();
            //获取所有要存储的学位篇名
            List<XW> list = this.getXWList();
            foreach (XW temp in list)
            {
                if (String.Empty.Equals(temp.Xw_flh))
                {
                    String message = temp.Xw_zwtm+":"+temp.Xw_zz+":"+temp.Xw_ds+":分类号为空";
                    result.Add(message);
                    continue;
                }
                //获取分类号，有分类号产生分类体系
                String fltx = "";
                Char begin = temp.Xw_flh[0];
                if (begin == 'T')
                {   //如果首字母为T，则需继续读取下一个字符
                    fltx='T'.ToString()+temp.Xw_flh[1].ToString();
                }
                else if (begin == 'o')
                {
                    //如果首字母为o，则分类体系为QQ
                    fltx = "QQ";
                }
                else
                {
                    //其他情况，则分类体系为首字母重复1次
                    fltx = begin.ToString() + begin.ToString();
                }

                if (!hash.Contains(fltx))
                {
                    String message = temp.Xw_zwtm + ":" + temp.Xw_zz + ":" + temp.Xw_ds + ":分类体系不存在";
                    result.Add(message);
                    continue;
                }

                //分类体系
                temp.Xw_fltx =  fltx;
                //分类编码=XW+分类体系
                temp.Xw_flbm = "XW" + fltx;
                //年份=原文件名的前4位
                temp.Xw_nf = temp.Xw_ywjm.Substring(0, 4);
                //索引编码=分类编码+"-"+年份
                temp.Xw_sybm = temp.Xw_flbm +"-"+ temp.Xw_nf;
            }
            return result;
        }


        /// <summary>
        /// 规整字段
        /// </summary>
        /// <param name="xw">要规整的记录</param>
        /// <returns>反馈规整信息，规整错误</returns>
        public String formatData(XW xw)
        {
            //反馈信息
            String result = null;
            //获取所有要存储的学位篇名
            if (String.Empty.Equals(xw.Xw_flh))
            {
                result = xw.Xw_zwtm + ":" + xw.Xw_zz + ":" + xw.Xw_ds + ":分类号为空";
            }
            else
            {
                //获取分类号，有分类号产生分类体系
                String fltx = "";
                Char begin = xw.Xw_flh[0];
                if (begin == 'T')
                {   //如果首字母为T，则需继续读取下一个字符
                    fltx = 'T'.ToString() + xw.Xw_flh[1].ToString();
                }
                else if (begin == 'o')
                {
                    //如果首字母为o，则分类体系为QQ
                    fltx = "QQ";
                }
                else
                {
                    //其他情况，则分类体系为首字母重复1次
                    fltx = begin.ToString() + begin.ToString();
                }

                if (!this.Hash.Contains(fltx))
                {
                    result = xw.Xw_zwtm + ":" + xw.Xw_zz + ":" + xw.Xw_ds + ":分类体系不存在";
                }

                //分类体系
                xw.Xw_fltx = fltx;
                //分类编码=XW+分类体系
                xw.Xw_flbm = "XW" + fltx;
                //年份=原文件名的前4位
                xw.Xw_nf = xw.Xw_ywjm.Substring(0, 4);
                //索引编码=分类编码+"-"+年份
                xw.Xw_sybm = xw.Xw_flbm + "-" + xw.Xw_nf;
            }
            return result;
        }


        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="xw">要更新的学位论文信息</param>
        /// <returns>更新结果，true更新成功；false更新成功</returns>
        public Boolean updateXW(XW xw)
        {
            //打开连接
            this.openOleDbConnection();

            //sql语句
            OleDbCommand sqlcmd = new OleDbCommand(@"update xw set 分类编码=@分类编码,索引编码=@索引编码,分类体系=@分类体系,年份=@年份,文件名=@文件名,全文=@全文 where 中文题名=@中文题名 and 作者=@作者 and 导师=@导师", this.ObjConnection);
            
            sqlcmd.Parameters.Add(new OleDbParameter("分类编码", xw.Xw_flbm));
            sqlcmd.Parameters.Add(new OleDbParameter("索引编码", xw.Xw_sybm));
            sqlcmd.Parameters.Add(new OleDbParameter("分类体系", xw.Xw_fltx));
            sqlcmd.Parameters.Add(new OleDbParameter("年份",xw.Xw_nf));
            sqlcmd.Parameters.Add(new OleDbParameter("文件名", xw.Xw_wjm));
            sqlcmd.Parameters.Add(new OleDbParameter("全文", xw.Xw_qw));
            sqlcmd.Parameters.Add(new OleDbParameter("中文题名", xw.Xw_zwtm));
            sqlcmd.Parameters.Add(new OleDbParameter("作者", xw.Xw_zz));
            sqlcmd.Parameters.Add(new OleDbParameter("导师", xw.Xw_ds));
            int back=sqlcmd.ExecuteNonQuery();
            if (back == 0)
            {
                return false;
            }
            //objConnection.Close();
            return true;
        }

        /// <summary>
        /// 本地Access库去重
        /// </summary>
        /// <param name="xw"></param>
        public void removeDuplicate(XW xw)
        {
            //打开Access连接
            this.openOleDbConnection();

            //sql语句
            OleDbCommand sqlcmd = new OleDbCommand();
            sqlcmd.CommandText = @"select * from xw where 中文题名=@中文题名 and 作者=@作者 and 导师=@导师";
            sqlcmd.Connection = this.ObjConnection;
            sqlcmd.Parameters.Add(new OleDbParameter("中文题名", xw.Xw_zwtm));
            sqlcmd.Parameters.Add(new OleDbParameter("作者", xw.Xw_zz));
            sqlcmd.Parameters.Add(new OleDbParameter("导师", xw.Xw_ds));

            OleDbDataReader oda= sqlcmd.ExecuteReader();
            int back = 0;
            while(oda.Read())
            {
                back++;
            }
            oda.Close();
            sqlcmd.Parameters.Clear();

            if (back >= 2)
            {
                //sqlcmd = new OleDbCommand(@"delete from xw  where 中文题名='" + xw.Xw_zwtm + "' and 作者='" + xw.Xw_zz + "' and 导师='" + xw.Xw_ds + "'", this.ObjConnection);
                sqlcmd.CommandText = @"delete from xw  where 中文题名=@中文题名 and 作者=@作者 and 导师=@导师";
                sqlcmd.Parameters.Add(new OleDbParameter("中文题名", xw.Xw_zwtm));
                sqlcmd.Parameters.Add(new OleDbParameter("作者", xw.Xw_zz));
                sqlcmd.Parameters.Add(new OleDbParameter("导师", xw.Xw_ds));
                sqlcmd.ExecuteNonQuery();
                sqlcmd.Parameters.Clear();

                sqlcmd.CommandText = @"insert into xw(中文题名,英文题名,作者,导师,论文级别,学科专业名称,分类号,学位授予单位,论文提交日期,论文答辩日期,中文关键词,中文摘要,英文摘要,年份,英文关键词,原文件名,出版日期,页数,学位授予日期,分类编码,索引编码,文件名,分类体系,更新日期,全文) values(@中文题名,@英文题名,@作者,@导师,@论文级别,@学科专业名称,@分类号,@学位授予单位,@论文提交日期,@论文答辩日期,@中文关键词,@中文摘要,@英文摘要,@年份,@英文关键词,@原文件名,@出版日期,@页数,@学位授予日期,@分类编码,@索引编码,@文件名,@分类体系,@更新日期,@全文)";
                sqlcmd.Parameters.Add(new OleDbParameter("中文题名", xw.Xw_zwtm));
                sqlcmd.Parameters.Add(new OleDbParameter("英文题名", xw.Xw_ywtm));
                sqlcmd.Parameters.Add(new OleDbParameter("作者", xw.Xw_zz));
                sqlcmd.Parameters.Add(new OleDbParameter("导师", xw.Xw_ds));
                sqlcmd.Parameters.Add(new OleDbParameter("论文级别", xw.Xw_lwjb));
                sqlcmd.Parameters.Add(new OleDbParameter("学科专业名称", xw.Xw_xkzymc));
                sqlcmd.Parameters.Add(new OleDbParameter("分类号", xw.Xw_flh));
                sqlcmd.Parameters.Add(new OleDbParameter("学科授予单位", xw.Xw_xwsydw));
                sqlcmd.Parameters.Add(new OleDbParameter("论文提交日期", xw.Xw_lwtjrq));
                sqlcmd.Parameters.Add(new OleDbParameter("论文答辩日期", xw.Xw_lwdbrq));
                sqlcmd.Parameters.Add(new OleDbParameter("中文关键词", xw.Xw_zwgjc));
                sqlcmd.Parameters.Add(new OleDbParameter("中文摘要", xw.Xw_zwzy));
                sqlcmd.Parameters.Add(new OleDbParameter("英文摘要", xw.Xw_ywzy));
                sqlcmd.Parameters.Add(new OleDbParameter("年份", xw.Xw_nf));
                sqlcmd.Parameters.Add(new OleDbParameter("英文关键词", xw.Xw_ywgjc));
                sqlcmd.Parameters.Add(new OleDbParameter("原文件名", xw.Xw_ywjm));
                sqlcmd.Parameters.Add(new OleDbParameter("出版日期", xw.Xw_cbrq));
                sqlcmd.Parameters.Add(new OleDbParameter("页数", xw.Xw_ys));
                sqlcmd.Parameters.Add(new OleDbParameter("学位授予日期", xw.Xw_xwsyrq));
                sqlcmd.Parameters.Add(new OleDbParameter("分类编码", xw.Xw_flbm));
                sqlcmd.Parameters.Add(new OleDbParameter("索引编码", xw.Xw_sybm));
                sqlcmd.Parameters.Add(new OleDbParameter("文件名", xw.Xw_wjm));
                sqlcmd.Parameters.Add(new OleDbParameter("分类体系", xw.Xw_fltx));
                sqlcmd.Parameters.Add(new OleDbParameter("更新日期", xw.Xw_gxrq));
                sqlcmd.Parameters.Add(new OleDbParameter("全文", xw.Xw_qw));
                sqlcmd.ExecuteNonQuery();
                sqlcmd.Parameters.Clear();

            }

        }

        /// <summary>
        /// 主库查重
        /// </summary>
        /// <param name="xw"></param>
        /// <returns>true:说明主库中已存在该记录；false:说明主库中不存在该记录</returns>
        public Boolean findDuplicate(XW xw)
        {
            //建立连接
            SqlConnection conn = Connection.CONN;
            Connection.openConnection();
            //命令行
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select * from XW where xw_zwtm=@xw_zwtm and xw_zz=@xw_zz and xw_ds=@xw_ds";
            cmd.Parameters.Add(new SqlParameter("xw_zwtm",xw.Xw_zwtm));
            cmd.Parameters.Add(new SqlParameter("xw_zz", xw.Xw_zz));
            cmd.Parameters.Add(new SqlParameter("xw_ds", xw.Xw_ds));

            SqlDataReader sda=cmd.ExecuteReader();
            if (sda.Read())
            {
                sda.Close();
                return true;
            }
            sda.Close();
            return false;
        }

        /// <summary>
        /// 向主库中添加一条新记录
        /// </summary>
        /// <param name="xw">要添加的新记录</param>
        /// <returns>true添加成功；false添加失败</returns>
        public String addRecord(XW xw)
        {
            //建立连接
            SqlConnection conn = Connection.CONN;
            //打开连接
            Connection.openConnection();
            //新建命令
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;

            //cmd.CommandText = "insert into XW(xw_flbm,xw_sybm,xw_wjm,xw_zwtm,xw_ywtm,xw_zz,xw_ds,xw_lwjb,xw_xkzymc,xw_flh,xw_xwsydw,xw_lwtjrq,xw_lwdbrq,xw_zwgjc,xw_zwzy,xw_fltx,xw_ywzy,xw_nf,xw_ywgjc,xw_ywjm,xw_cbrq,xw_ys,xw_xwsyrq,xw_gxrq,xw_qw) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            cmd.CommandText = "insert into XW(xw_flbm,xw_sybm,xw_wjm,xw_zwtm,xw_ywtm,xw_zz,xw_ds,xw_lwjb,xw_xkzymc,xw_flh,xw_xwsydw,xw_lwtjrq,xw_lwdbrq,xw_zwgjc,xw_zwzy,xw_fltx,xw_ywzy,xw_nf,xw_ywgjc,xw_ywjm,xw_cbrq,xw_ys,xw_xwsyrq,xw_gxrq,xw_qw) values(@xw_flbm,@xw_sybm,@xw_wjm,@xw_zwtm,@xw_ywtm,@xw_zz,@xw_ds,@xw_lwjb,@xw_xkzymc,@xw_flh,@xw_xwsydw,@xw_lwtjrq,@xw_lwdbrq,@xw_zwgjc,@xw_zwzy,@xw_fltx,@xw_ywzy,@xw_nf,@xw_ywgjc,@xw_ywjm,@xw_cbrq,@xw_ys,@xw_xwsyrq,@xw_gxrq,@xw_qw)";
            
            DateTime MIN=DateTime.Parse("1/1/1753");
            cmd.Parameters.Add(new SqlParameter("xw_flbm",xw.Xw_flbm));
            cmd.Parameters.Add(new SqlParameter("xw_sybm", xw.Xw_sybm));
            cmd.Parameters.Add(new SqlParameter("xw_wjm", xw.Xw_wjm));
            cmd.Parameters.Add(new SqlParameter("xw_zwtm", xw.Xw_zwtm));
            cmd.Parameters.Add(new SqlParameter("xw_ywtm", xw.Xw_ywtm));

            cmd.Parameters.Add(new SqlParameter("xw_zz", xw.Xw_zz));
            cmd.Parameters.Add(new SqlParameter("xw_ds", xw.Xw_ds));
            cmd.Parameters.Add(new SqlParameter("xw_lwjb", xw.Xw_lwjb));
            cmd.Parameters.Add(new SqlParameter("xw_xkzymc", xw.Xw_xkzymc));
            cmd.Parameters.Add(new SqlParameter("xw_flh", xw.Xw_flh));
            cmd.Parameters.Add(new SqlParameter("xw_xwsydw", xw.Xw_xwsydw));

            if (xw.Xw_lwtjrq.CompareTo(MIN) <= 0)
            {
                cmd.Parameters.Add(new SqlParameter("xw_lwtjrq", MIN));
            }
            else
            {
                cmd.Parameters.Add(new SqlParameter("xw_lwtjrq", xw.Xw_lwtjrq));
            }
            if (xw.Xw_lwdbrq.CompareTo(MIN) <= 0)
            {
                cmd.Parameters.Add(new SqlParameter("xw_lwdbrq", MIN));
            }
            else
            {
                cmd.Parameters.Add(new SqlParameter("xw_lwdbrq", xw.Xw_lwdbrq));
            }
            cmd.Parameters.Add(new SqlParameter("xw_zwgjc", xw.Xw_zwgjc));
            cmd.Parameters.Add(new SqlParameter("xw_zwzy", xw.Xw_zwzy));

            cmd.Parameters.Add(new SqlParameter("xw_fltx", xw.Xw_fltx));
            cmd.Parameters.Add(new SqlParameter("xw_ywzy", xw.Xw_ywzy));
            cmd.Parameters.Add(new SqlParameter("xw_nf", xw.Xw_nf));
            cmd.Parameters.Add(new SqlParameter("xw_ywgjc", xw.Xw_ywgjc));
            cmd.Parameters.Add(new SqlParameter("xw_ywjm", xw.Xw_ywjm));

            if (xw.Xw_cbrq.CompareTo(MIN) <= 0)
            {
                cmd.Parameters.Add(new SqlParameter("xw_cbrq", MIN));
            }
            else
            {
                cmd.Parameters.Add(new SqlParameter("xw_cbrq", xw.Xw_cbrq));
            }
            //cmd.Parameters.Add(new SqlParameter("xw_cbrq", xw.Xw_cbrq));
            cmd.Parameters.Add(new SqlParameter("xw_ys", xw.Xw_ys));
            if (xw.Xw_xwsyrq.CompareTo(MIN) <= 0)
            {
                cmd.Parameters.Add(new SqlParameter("xw_xwsyrq", MIN));
            }
            else
            {
                cmd.Parameters.Add(new SqlParameter("xw_xwsyrq", xw.Xw_xwsyrq));
            }
            //cmd.Parameters.Add(new SqlParameter("xw_xwsyrq", xw.Xw_xwsyrq));
            cmd.Parameters.Add(new SqlParameter("xw_gxrq", DateTime.Now));
            cmd.Parameters.Add(new SqlParameter("xw_qw", xw.Xw_qw));
            int back = 0;
            try
            {
                back = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

                return ex.Message;
            }
            if (back == 0)
                return "插入记录失败！！！";
            return null;
        }
    }
}
